local skel = fk.CreateSkill {
  name = "efengqi__jijie",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["efengqi__jijie"] = "机捷",
  [":efengqi__jijie"] = "锁定技，牌堆底的牌对你可见。你摸仅一张牌时，改为从牌堆底摸。",
  ["@[fqjj]efengqi__jijie"] = "机捷",

  ["$efengqi__jijie1"] = "一拜一起，未足为劳。",
  ["$efengqi__jijie2"] = "识言观行，方能雍容风议。",
}

skel:addEffect(fk.BeforeDrawCard, {
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.num == 1 and data.fromPlace ~= "bottom"
  end,
  on_use = function (self, event, target, player, data)
    data.fromPlace = "bottom"
  end,
})

local function updataMark(player)
  local room = player.room
  local cid = room.draw_pile[#room.draw_pile]
  room:setPlayerMark(player, "@[fqjj]efengqi__jijie", cid or 0)
end

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(skel.name, true) then
      if table.find(data, function(move)
        return table.find(move.moveInfo, function(info) return info.fromArea == Card.DrawPile end) ~= nil or move.toArea == Card.DrawPile
      end) then
        return true
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    updataMark(player)
  end,
})

skel:addEffect(fk.AfterDrawPileShuffle, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = function(self, event, target, player, data)
    updataMark(player)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  updataMark(player)
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@[fqjj]efengqi__jijie", 0)
end)

Fk:addQmlMark{
  name = "fqjj",
  qml_path = "",
  how_to_show = function(name, value, observer)
    local skill
    local pos = string.find(name, "]", 1, true)
    if pos then
      skill = string.sub(name, pos + 1)
    end
    local cid = tonumber(value)
    if cid and cid ~= 0 and observer == Self and skill and Self:hasSkill(skill) then
      return Fk:getCardById(cid):toLogString()
    end
    return " "
  end,
}

return skel
